# coding=utf-8
import time
import selenium
import os
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
import unittest


def yunshanfu_pay(buytime):
    while True:
        start_time = time.strftime('%Y-%m-%d %H:%M:%S')
        if start_time > buytime:
            print(start_time, '开始付款！')
            desired_caps = {
                "platformName": "Android",
                "platformVersion": "9",
                "deviceName": "c0bea597",
                "appPackage": "com.unionpay",
                "appActivity": "com.unionpay.activity.UPActivityWelcome",
                "noReset": "True"
            }
            print("首次启动云闪付APP中···比较慢")
            driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
            time.sleep(2)
            for num in range(100):
                print("第", num + 1, "次支付")
                try:
                    btn = driver.find_element_by_id("com.unionpay:id/tv_tab_name")
                except Exception as e:
                    print("Exception found", format(e))
                    break
                else:
                    print("单击收付款···")
                    btn.click()
                    driver.implicitly_wait(5)
                    driver.find_element_by_id("com.unionpay:id/tv_tab_name").click()
                    print("滑动进入扫码界面···")
                    size = driver.get_window_size()
                    width = size['width']
                    height = size['height']
                    y1 = height * 0.5
                    y2 = height * 0.2
                    x1 = width * 0.5
                    driver.swipe(x1, y1, x1, y2)
                    print("本地图库添加二维码收款码···")
                    driver.find_element_by_id("com.unionpay:id/tvOpenAlbum").click()  # 打开相册，需更改坐标
                    time.sleep(0.5)
                    os.system("adb -s c0bea597 shell input tap 133 611 ")  # 选择图库中的照片的位置（放在首张），需更改坐标
                    time.sleep(0.5)
                    os.system("adb -s c0bea597 shell input tap 771 2155 ")  # 点击确定，需更改坐标
                    # print('输入金额···')
                    # time.sleep(2)
                    #  os.system("adb -s c0bea597 shell input tap 135 1699 ")  # 金服台卡，需输入金额，可注释
                    #  os.system("adb -s c0bea597 shell input tap 942 1872 ")  # 金服台卡，输入收款键，可注释
                    try:  # 当日第一次进入时登录OA账号
                        btn = driver.find_element_by_id('android:id/button1')
                    except Exception as e:
                        print("Exception found", format(e))
                        try:
                            btn = driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                                '.widget.RelativeLayout['
                                '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                                '/android.view.View/android.view.View/android.widget.Spinner')
                        except Exception as e:
                            print("Exception found", format(e))
                            try:  # 遇到支付信息失败情况时
                                btn = driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget'
                                    '.LinearLayout/android.widget.FrameLayout/android.widget'
                                    '.LinearLayout/android.widget.FrameLayout/android.view'
                                    '.ViewGroup/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup[1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup[3]/android.view.ViewGroup/android.view.ViewGroup')
                            except Exception as e:
                                print("Exception found", format(e))
                                break
                                # for i in range(4):
                                # os.system('adb -s c0bea597 shell input keyevent 4')
                                # size = driver.get_window_size()
                                # width = size['width']
                                # height = size['height']
                                # y1 = height * 0.5
                                # y2 = height * 0.2
                                # x1 = width * 0.5
                                # driver.swipe(x1, y1, x1, y2)
                                # print("本地图库添加二维码收款码···")
                                # driver.find_element_by_id("com.unionpay:id/tvOpenAlbum").click()  # 打开相册，需更改坐标
                                # time.sleep(0.5)
                                # os.system("adb -s c0bea597 shell input tap 133 611 ")  # 选择图库中的照片的位置（放在首张），需更改坐标
                                # time.sleep(0.5)
                                # os.system("adb -s c0bea597 shell input tap 771 2155 ")  # 点击确定，需更改坐标
                                # btn = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android'
                                #                                        '.widget.LinearLayout/android.widget.FrameLayout'
                                #                                        '/android.widget.LinearLayout/android.widget'
                                #                                        '.FrameLayout/android.view.ViewGroup/android.view'
                                #                                        '.ViewGroup/android.view.ViewGroup/android.view'
                                #                                        '.ViewGroup[1]/android.view.ViewGroup['
                                #                                        '2]/android.view.ViewGroup/android.view.ViewGroup'
                                #                                        '/android.view.ViewGroup['
                                #                                        '3]/android.view.ViewGroup/android.view.ViewGroup')
                                # if btn:
                                #     print("点击确认付款···")
                                #     # time.sleep(2)
                                #     os.system('adb -s c0bea597 shell input tap 539 2129 ')  # 点击确认收款，需更改坐标
                                #     print('输入密码中···')
                                #     driver.find_element_by_xpath(
                                #             '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                #             '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                #             '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                #             '/android.view.ViewGroup/android.view.ViewGroup['
                                #             '1]/android.view.ViewGroup['
                                #             '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                #             '.ViewGroup['
                                #             '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                #             '.widget.GridView/android.widget.RelativeLayout['
                                #             '1]/android.widget.FrameLayout/android.widget.TextView').click()
                                #     driver.find_element_by_xpath(
                                #             '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                #             '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                #             '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                #             '/android.view.ViewGroup/android.view.ViewGroup['
                                #             '1]/android.view.ViewGroup['
                                #             '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                #             '.ViewGroup['
                                #             '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                #             '.widget.GridView/android.widget.RelativeLayout['
                                #             '4]/android.widget.FrameLayout/android.widget.TextView').click()
                                #     driver.find_element_by_xpath(
                                #             '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                #             '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                #             '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                #             '/android.view.ViewGroup/android.view.ViewGroup['
                                #             '1]/android.view.ViewGroup['
                                #             '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                #             '.ViewGroup['
                                #             '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                #             '.widget.GridView/android.widget.RelativeLayout['
                                #             '2]/android.widget.FrameLayout/android.widget.TextView').click()
                                #     driver.find_element_by_xpath(
                                #             '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                #             '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                #             '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                #             '/android.view.ViewGroup/android.view.ViewGroup['
                                #             '1]/android.view.ViewGroup['
                                #             '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                #             '.ViewGroup['
                                #             '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                #             '.widget.GridView/android.widget.RelativeLayout['
                                #             '5]/android.widget.FrameLayout/android.widget.TextView').click()
                                #     driver.find_element_by_xpath(
                                #             '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                #             '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                #             '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                #             '/android.view.ViewGroup/android.view.ViewGroup['
                                #             '1]/android.view.ViewGroup['
                                #             '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                #             '.ViewGroup['
                                #             '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                #             '.widget.GridView/android.widget.RelativeLayout['
                                #             '3]/android.widget.FrameLayout/android.widget.TextView').click()
                                #     driver.find_element_by_xpath(
                                #             '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                #             '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                #             '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                #             '/android.view.ViewGroup/android.view.ViewGroup['
                                #             '1]/android.view.ViewGroup['
                                #             '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                #             '.ViewGroup['
                                #             '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                #             '.widget.GridView/android.widget.RelativeLayout['
                                #             '6]/android.widget.FrameLayout/android.widget.TextView').click()
                                #     time.sleep(2)
                                #     os.system('adb -s c0bea597 shell input tap 985 149')  # 点击完成，需更改坐标
                                #         # time.sleep(2)
                                #         # for back in range(2):
                                #         #     os.system('adb -s c0bea597 shell input keyevent 4')  # 金服台卡需要，可注释
                                #     print("支付成功···")
                            else:
                                print("点击确认付款···")
                                # time.sleep(2)
                                os.system('adb -s c0bea597 shell input tap 539 2129 ')  # 点击确认收款，需更改坐标
                                print('输入密码中···')
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '1]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '4]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '2]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '5]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '3]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '6]/android.widget.FrameLayout/android.widget.TextView').click()
                                time.sleep(2)
                                os.system('adb -s c0bea597 shell input tap 985 149')  # 点击完成，需更改坐标
                                # time.sleep(2)
                                # for back in range(2):
                                #     os.system('adb -s c0bea597 shell input keyevent 4')  # 金服台卡需要，可注释
                                print("支付成功···")

                        else:
                            btn.click()
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout'
                                '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                '.widget.FrameLayout/android.widget.FrameLayout/android.widget'
                                '.ListView/android.widget.CheckedTextView[2]').click()
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                                '.widget.RelativeLayout['
                                '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                                '/android.view.View/android.view.View/android.widget.EditText['
                                '1]').send_keys('17620533205')
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                                '.widget.RelativeLayout['
                                '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                                '/android.view.View/android.view.View/android.widget.EditText['
                                '2]').send_keys('12345678')
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                                '.widget.RelativeLayout['
                                '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                                '/android.view.View/android.view.View/android.widget.Button').click()

                            try:  # 遇到支付信息失败情况时
                                btn = driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget'
                                    '.LinearLayout/android.widget.FrameLayout/android.widget'
                                    '.LinearLayout/android.widget.FrameLayout/android.view'
                                    '.ViewGroup/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup[1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup[3]/android.view.ViewGroup/android.view.ViewGroup')
                            except Exception as e:
                                print("Exception found", format(e))
                                break
                            else:
                                print("点击确认付款···")
                                time.sleep(2)
                                os.system('adb -s c0bea597 shell input tap 539 2129 ')  # 点击确认收款，需更改坐标
                                print('输入密码中···')
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '1]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '4]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '2]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '5]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '3]/android.widget.FrameLayout/android.widget.TextView').click()
                                driver.find_element_by_xpath(
                                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                    '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                    '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                    '/android.view.ViewGroup/android.view.ViewGroup['
                                    '1]/android.view.ViewGroup['
                                    '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                    '.ViewGroup['
                                    '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                    '.widget.GridView/android.widget.RelativeLayout['
                                    '6]/android.widget.FrameLayout/android.widget.TextView').click()
                                time.sleep(2)
                                os.system('adb -s c0bea597 shell input tap 985 149')  # 点击完成，需更改坐标
                                # time.sleep(2)
                                # for back in range(2):
                                #     os.system('adb -s c0bea597 shell input keyevent 4')  # 金服台卡需要，可注释
                                print("支付成功···")
                    else:
                        btn.click()
                        driver.find_element_by_xpath(
                            '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                            '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                            '.widget.RelativeLayout['
                            '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                            '/android.view.View/android.view.View/android.widget.Spinner').click()
                        driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout'
                                                     '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                                     '.widget.FrameLayout/android.widget.FrameLayout/android.widget'
                                                     '.ListView/android.widget.CheckedTextView[2]').click()
                        driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                                     '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                                                     '.widget.RelativeLayout['
                                                     '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                                                     '/android.view.View/android.view.View/android.widget.EditText['
                                                     '1]').send_keys('17620533205')
                        driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                                     '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                                                     '.widget.RelativeLayout['
                                                     '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                                                     '/android.view.View/android.view.View/android.widget.EditText['
                                                     '2]').send_keys('12345678')
                        driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                                     '/android.widget.FrameLayout/android.widget.RelativeLayout/android'
                                                     '.widget.RelativeLayout['
                                                     '2]/android.webkit.WebView/android.webkit.WebView/android.view.View'
                                                     '/android.view.View/android.view.View/android.widget.Button').click()

                        try:  # 遇到支付信息失败情况时
                            btn = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/android.widget'
                                                               '.LinearLayout/android.widget.FrameLayout/android.widget'
                                                               '.LinearLayout/android.widget.FrameLayout/android.view'
                                                               '.ViewGroup/android.view.ViewGroup/android.view.ViewGroup'
                                                               '/android.view.ViewGroup[1]/android.view.ViewGroup['
                                                               '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                                               '.ViewGroup[3]/android.view.ViewGroup/android.view.ViewGroup')
                        except Exception as e:
                            print("Exception found", format(e))
                            break
                        else:
                            print("点击确认付款···")
                            time.sleep(2)
                            os.system('adb -s c0bea597 shell input tap 539 2129 ')  # 点击确认收款，需更改坐标
                            print('输入密码中···')
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                '/android.view.ViewGroup/android.view.ViewGroup['
                                '1]/android.view.ViewGroup['
                                '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                '.ViewGroup['
                                '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                '.widget.GridView/android.widget.RelativeLayout['
                                '1]/android.widget.FrameLayout/android.widget.TextView').click()
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                '/android.view.ViewGroup/android.view.ViewGroup['
                                '1]/android.view.ViewGroup['
                                '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                '.ViewGroup['
                                '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                '.widget.GridView/android.widget.RelativeLayout['
                                '4]/android.widget.FrameLayout/android.widget.TextView').click()
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                '/android.view.ViewGroup/android.view.ViewGroup['
                                '1]/android.view.ViewGroup['
                                '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                '.ViewGroup['
                                '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                '.widget.GridView/android.widget.RelativeLayout['
                                '2]/android.widget.FrameLayout/android.widget.TextView').click()
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                '/android.view.ViewGroup/android.view.ViewGroup['
                                '1]/android.view.ViewGroup['
                                '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                '.ViewGroup['
                                '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                '.widget.GridView/android.widget.RelativeLayout['
                                '5]/android.widget.FrameLayout/android.widget.TextView').click()
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                '/android.view.ViewGroup/android.view.ViewGroup['
                                '1]/android.view.ViewGroup['
                                '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                '.ViewGroup['
                                '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                '.widget.GridView/android.widget.RelativeLayout['
                                '3]/android.widget.FrameLayout/android.widget.TextView').click()
                            driver.find_element_by_xpath(
                                '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout'
                                '/android.widget.FrameLayout/android.widget.LinearLayout/android'
                                '.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup'
                                '/android.view.ViewGroup/android.view.ViewGroup['
                                '1]/android.view.ViewGroup['
                                '2]/android.view.ViewGroup/android.view.ViewGroup/android.view'
                                '.ViewGroup['
                                '3]/android.view.ViewGroup/android.widget.LinearLayout/android'
                                '.widget.GridView/android.widget.RelativeLayout['
                                '6]/android.widget.FrameLayout/android.widget.TextView').click()
                            time.sleep(2)
                            os.system('adb -s c0bea597 shell input tap 985 149')  # 点击完成，需更改坐标
                            # time.sleep(2)
                            # for back in range(2):
                            #     os.system('adb -s c0bea597 shell input keyevent 4')  # 金服台卡需要，可注释
                            print("支付成功···")


yunshanfu_pay('2019-09-21 12:00:00')
